﻿<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8"/>
  <title></title>
  <link href="/style/rightdirectory.css" rel="stylesheet"/>
  <script src="/script/list-config.js"></script>
</head>
<style>
  th {
    text-align: center;
  }

  td {
    text-align: center;
  }

</style>
<body>
<div class="view-page">
  <!--搜索区域-->
  <div class="view-search inline">
    <div class="form-inline">
      <div class="form-group col-xs-2">
          <div class="input-group">
              <span class="input-group-addon">产品名称</span>
              <input id="query" type="text" class="form-control" data-form="Product_Id" placeholder="产品名称">
          </div>
      </div>
      <div class="form-group col-xs-1">
        <button type="button" id="btn-search" class="btn btn-primary">
          <i class="fa fa-search"></i> 搜索
        </button>
      </div>
    </div>
  </div>
  <div class="view-eidt-btns">
    <a href="javascript:;" class="btn btn-sm" data-btn-eidt="/views/mall/Product/sku/edit.html?v=">
      <i class="fa fa-edit"></i>添加/修改
    </a>
  </div>
  <div class="view-data">
    <table id="table" class="table table-bordered table-hover" data-post="">
      <thead>
      <tr>
        <th class="checkboxs">
          <label class="checkbox-reset">
            <input type="checkbox" data-checked-table="all"/>
          </label>
        </th>
        <th>产品 Id</th>
        <th>SKU名称</th>
        <th>属性组合值</th>
        <th>SKU图片选择</th>
        <th>原价</th>
        <th>商品目前出售价格</th>
        <th>商品库存</th>
        <th>操作</th>
      </tr>
      </thead>
      <tbody></tbody>
    </table>
    <!--分页 默认选择id=list-page元素-->
    <div id="list-page" class="view-pagination-page"></div>
  </div>
</div>
</body>

</html>
<script type="text/html" id="tp-table">
  {{each list d}}
  <tr data-eidt="{{d.Product_Id}}|{{d.SkuProperty}}">
    <td class="checkboxs">
      <label class="checkbox-reset">
        <input type="checkbox" value="{{d.Product_Id}}" data-checked-table="single"/>
      </label>
    </td>
    <td class="pId">{{d.Product_Id}}</td>
    <td>{{d.SkuName}}</td>
    <td class="prop">{{d.SkuProperty}}</td>
    <td><img src="{{d.SkuPropertyPic}}" style="width:40px;height:30px;"/></td>
    <td>{{d.OriginalPrice}}</td>
    <td>{{d.SellPrice}}</td>
    <td>{{d.Inventory}}</td>
    <td><button class="btn btn-danger" onclick="del(this)">删除</button></td>
  </tr>
  {{/each}}
</script>

<script type="text/javascript">
  $(function () {
    function _LoadData() {
      var parm = $(".view-search").getFormData();
      $("#table").ajaxPageTable("pattrsku/list", parm, function (d) {
        
        $("#table>tbody").append(template("tp-table", {
          list: d
        }));
      })
    }

    _LoadData();//初启化
    $("#query").focus(function () { //搜索按钮
      $("#query").keydown(function (e) {
        if (e.keyCode == 13) {
          _LoadData();
        }
      })
    })
    $("#btn-search").click(function () { //搜索按钮
      _LoadData();
    })
  })

  // 删除
  function del(el) {
    var request = {
      Product_Id:parseInt($(el).parent('td').siblings('.pId').text()),
      SkuProperty:$(el).parent('td').siblings('.prop').text()
    };
    $.alert("确定要删除嘛？", function () {
      console.log(request)
      $.http.json("pattrsku/del", request, {
        pass: function (data) {
          console.log(data);
          $.msgSucceed("删除成功");
          setTimeout(function () {
            window.location.reload();
          }, 1000)
        },
        error: function (d) {
          console.log(d);
        }
      })
    })
  }
</script>